package siac.com.util;

import java.util.Date;

//Immutable class that uses defensive copying
public final class EmbeddablePeriodoAsDate {
	private final Date start;
	private final Date end;

	/**
	 * @param start
	 *            the beginning of the period.
	 * @param end
	 *            the end of the period; must not precede start.
	 * @throws IllegalArgument
	 *             if start is after end.
	 * @throws NullPointerException
	 *             if start or end is null.
	 */
	public EmbeddablePeriodoAsDate(Date start, Date end) {
		this.start = new Date(start.getTime());
		this.end = new Date(end.getTime());

		if (this.start.compareTo(this.end) > 0)
			throw new IllegalArgumentException(start + " > " + end);
	}

	public Date start() {
		return (Date) start.clone();
	}

	public Date end() {
		return (Date) end.clone();
	}

	public String toString() {
		return start + " - " + end;
	}
}
